import Vue from 'vue'
import Router from 'vue-router'

const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

const originalReplace = Router.prototype.replace
Router.prototype.replace = function replace(location) {
  return originalReplace.call(this, location).catch(err => err)
}

const Home = () => import('@/components/home')

const SearchResult = () => import('@/components/searchResult')

const Release = () => import('@/components/release')
const Seek = () => import('@/components/seek')

const Login = () => import('@/components/login')

const Profile = () => import('@/components/profile')
const UserInfo = () => import('@/components/profile/userinfo')
const Goods = () => import('@/components/profile/goods')
const Shopcart = () => import('@/components/profile/shopcart')
const Colloection = () => import('@/components/profile/collection')
const Message = () => import('@/components/profile/message')
const MyRelease = () => import('@/components/profile/myRelease')

const Register = () => import('@/components/register')

const GoodsDetail = () => import('@/components/goodsDetail')

const Blank = () => import('@/components/home/search/searchBlank')

Vue.use(Router)

const routes = [
  {
    path: '',
    redirect: '/home'
  },
  {
    path: '/home',
    name: 'Home',
    component: Home,
  },
  {
    path: '/search_result',
    component: SearchResult
  },
  {
    path: '/login',
    component: Login
  },
  {
    path: '/profile',
    component: Profile,
    children: [
      {
        path: '',
        redirect: 'userinfo'
      },
      {
        path: 'userinfo',
        component: UserInfo
      },
      {
        path: 'goods',
        component: Goods
      },
      {
        path: 'shopcart',
        component: Shopcart
      },
      {
        path: 'collection',
        component: Colloection
      },
      {
        path: 'message',
        component: Message
      },
      {
        path: 'myRelease',
        component: MyRelease
      }
    ]
  },
  {
    path: '/register',
    component: Register
  },
  {
    path: '/release',
    component: Release
  },
  {
    path: '/seek',
    component: Seek
  },
  {
    path: '/goodsDetail',
    component: GoodsDetail
  },
  {
    path: '/blank',
    component: Blank
  }
  
];

const router = new Router({
  routes,
  mode: 'history'
})

export default router
